package com.ruoyi.swla2.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.swla2.domain.TaskManagement;
import com.ruoyi.swla2.service.ITaskManagementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务管理Controller
 *
 * @author gdqt
 * @date 2025-06-26
 */
@RestController
@RequestMapping("/swla2/taskManagement")
public class TaskManagementController extends BaseController
{
    @Autowired
    private ITaskManagementService taskManagementService;

    /**
     * 查询任务管理列表
     */
    @PreAuthorize("@ss.hasPermi('swla2:taskManagement:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaskManagement taskManagement)
    {
        startPage();
        List<TaskManagement> list = taskManagementService.selectTaskManagementList(taskManagement);
        return getDataTable(list);
    }

    /**
     * 导出任务管理列表
     */
    @PreAuthorize("@ss.hasPermi('swla2:taskManagement:export')")
    @Log(title = "任务管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskManagement taskManagement)
    {
        List<TaskManagement> list = taskManagementService.selectTaskManagementList(taskManagement);
        ExcelUtil<TaskManagement> util = new ExcelUtil<TaskManagement>(TaskManagement.class);
        util.exportExcel(response, list, "任务管理数据");
    }

    /**
     * 获取任务管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('swla2:taskManagement:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(taskManagementService.selectTaskManagementById(id));
    }

    /**
     * 新增任务管理
     */
    @PreAuthorize("@ss.hasPermi('swla2:taskManagement:add')")
    @Log(title = "任务管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TaskManagement taskManagement)
    {
        List<TaskManagement> list = taskManagementService.list(new QueryWrapper<TaskManagement>().lambda().eq(TaskManagement::getTaskNo
                        ,taskManagement.getTaskNo()));
        if(null!=list && list.size()>0){
            return AjaxResult.error("任务编号重复！");
        }
        return toAjax(taskManagementService.insertTaskManagement(taskManagement));
    }

    /**
     * 修改任务管理
     */
    @PreAuthorize("@ss.hasPermi('swla2:taskManagement:edit')")
    @Log(title = "任务管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskManagement taskManagement)
    {
        return toAjax(taskManagementService.updateTaskManagement(taskManagement));
    }

    /**
     * 删除任务管理
     */
    @PreAuthorize("@ss.hasPermi('swla2:taskManagement:remove')")
    @Log(title = "任务管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(taskManagementService.deleteTaskManagementByIds(ids));
    }
}
